import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);

// 后台布局组件
import Layout from '@/views/layout/index';

// 静态路由
export const constantRoutes = [
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index'),
        hidden: true,
    },

    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },

    {
        path: '/',
        name: 'LayoutIndex',
        component: Layout,
        redirect: '/dashboard',
        meta: {
            title: '首页', icon: 'el-icon-menu'
        },
        children: [
            {
                path: '/dashboard',
                name: 'DashBoard',
                component: () => import('@/views/dashboard/index'),
                meta: {
                    title: '首页', icon: 'el-icon-menu'
                }
            }
        ]
    },
    {
        path: '/sys',
        name: 'SystemManage',
        component: Layout,
        redirect: '/sys/account',
        meta: {
            title: '系统管理', icon: 'el-icon-s-tools'
        },
        children: [
            {
                path: '/sys/account',
                name: 'AccountIndex',
                component: () => import('@/views/sys/account'),
                meta: {
                    title: '账号管理', icon: 'el-icon-user-solid'
                }
            },
            {
                path: '/sys/role',
                name: 'RoleIndex',
                component: () => import('@/views/sys/role'),
                meta: {
                    title: '角色管理', icon: 'el-icon-s-custom'
                }
            },
            {
                path: '/sys/menu',
                name: 'MenuIndex',
                component: () => import('@/views/sys/menu'),
                meta: {
                    title: '权限管理', icon: 'el-icon-success'
                }
            },
            {
                path: '/sys/dict',
                name: 'DictionaryIndex',
                component: () => import('@/views/dict/index'),
                meta: {
                    title: '数据字典', icon: 'el-icon-success'
                }
            },
        ]
    },

    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]

// 创建路由对象
const createRouter = () => new VueRouter({
    mode: 'history',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})
const router = createRouter()
// 重置路由对象
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}
// 导出路由对象
export default router;